from django.db import models
from django.utils import timezone
from psqlextra.manager import PostgresManager


class MyDataBase(models.Model):
    """
    1 商品id
    2 商品名称
    3 商品主图
    4 商品详情页链接地址
    5 商品一级类目
    6 淘宝客链接
    7 商品价格(单位：元)
    8 商品月销量
    9 收入比率(%)
    10 佣金
    11 卖家旺旺
    12 卖家id
    13 店铺名称
    14 平台类型
    15 优惠券id
    16 优惠券总量
    17 优惠券剩余量
    18 优惠券面额
    19 优惠券开始时间
    20 优惠券结束时间
    21 优惠券链接
    22 商品优惠券推广链接

    """
    objects = PostgresManager()
    # 货物
    goods_id = models.CharField(max_length=100, unique=True)
    goods_name = models.CharField(max_length=200)
    goods_image = models.CharField(max_length=200)
    goods_detail_url = models.CharField(max_length=255)
    goods_category = models.CharField(max_length=100)
    tbk_url = models.TextField()
    goods_price = models.FloatField()
    goods_sales = models.IntegerField()
    income_ratio = models.FloatField()
    commission = models.FloatField()  # 10
    # 卖家
    seller_wangwang = models.CharField(max_length=100)
    seller_id = models.CharField(max_length=100)
    shop_name = models.CharField(max_length=100)
    platform_type = models.CharField(max_length=100)
    # 优惠券
    coupon_id = models.CharField(max_length=100)
    coupon_total = models.IntegerField()
    coupon_surplus = models.IntegerField()  # 17
    coupon_value = models.CharField(max_length=100)
    discount_start = models.DateTimeField()  # 开始时间
    discount_end = models.DateTimeField()  # 结束时间
    coupon_url = models.TextField()
    goods_coupon_spread_url = models.TextField()
    update_at = models.DateTimeField(default=timezone.now)

    class Meta:
        abstract = True
        indexes = [
            models.Index(fields=['goods_id']),
            models.Index(fields=['discount_start']),
            models.Index(fields=['discount_end']),
        ]
        ordering = ['goods_name']


class GoodsDetail(models.Model):
    goods_id = models.CharField(max_length=100)
    links = models.TextField()
    update_at = models.DateTimeField(default=timezone.now)


class MyData(MyDataBase):
    pass


# xls 历史
class UploadHistory(models.Model):
    file_name = models.CharField(max_length=100)
    qq_uuid = models.CharField(max_length=200)
    upload_at = models.DateTimeField(default=timezone.now)
